$("#btn-follow").tooltip({
	animation:true,
	placement:"left",
	trigger:"manual",
});

$("#btn-follow.disabled").each(function(){
	set_unfollow_btn_anim();
});

var c_bid = -1;

function set_unfollow_btn(){
	set_unfollow_btn_anim();
	$("#btn-follow").html('Followed');
	$("#btn-follow").addClass('disabled');
	$("#btn-follow")[0].onclick = function(event){
		unfollow_blog(c_bid);
	};
}

function set_unfollow_btn_anim(){
	$("#btn-follow").attr('data-original-title','You Have Followed This Blog!');
	$("#btn-follow").unbind('mouseover');
	$("#btn-follow").unbind('mouseleave');
	$("#btn-follow").mouseover(function () {
		$(this).html('Unfollow');
		$("#btn-follow").removeClass('disabled');
		$('#btn-follow').tooltip('show');
	});
	$("#btn-follow").mouseleave(function () {
		$(this).html('Followed');
		$("#btn-follow").addClass('disabled');
		$('#btn-follow').tooltip('hide');
	});
}

function set_follow_btn_anim(){
	$("#btn-follow").attr('data-original-title','Follow This Bolg!');
	$("#btn-follow").unbind('mouseover');
	$("#btn-follow").unbind('mouseleave');
	$("#btn-follow").mouseover(function () {
		$('#btn-follow').tooltip('show');
	});
	$("#btn-follow").mouseleave(function () {
		$('#btn-follow').tooltip('hide');
	});
}

function set_follow_btn(){
	set_follow_btn_anim();
	$("#btn-follow").html('Follow');
	$("#btn-follow").removeClass('disabled');
	$("#btn-follow")[0].onclick = function(event){
		follow_blog(c_bid);
	};
}


function follow_blog(){
	if(arguments){
		c_bid = arguments[0];
	}	
	$.post('/MyMicroBlog/index.php/follow/',{
			bid:c_bid
		},
		function(data,state,rqst){
			set_unfollow_btn();
		});
}


function unfollow_blog(){
	if(arguments){
		c_bid = arguments[0];
	}
	
	$.post('/MyMicroBlog/index.php/follow/remove/',{
			bid:c_bid
		},
		function(data,state,rqst){
			set_follow_btn();
	});
}